<?php
pc_base::load_app_class('hchbase','hchindex',0);
class index extends hchbase {
    function __construct() {
        parent::__construct();
        $this->db = pc_base::load_model("myjobview_model"); //连接数据库
        $this->bulletInfo0 = '华创俱乐部 HCCLUB';
        $this->bulletInfo1 = '人才对接';
        $this->bulletInfo2 = '招聘模块';
    }

    function init(){
        $keyword = safe_replace($_GET['keyword']);
        $years_start = $_GET['years_start'];    //工作年限上限
        $years_end = $_GET['years_end'];        //工作年限下限
        $date = $_GET['date'];                  //发布日期
        $edu = $_GET['edu'];                    //学历要求
        $salary_start = $_GET['salary_start'];  //月薪范围下限
        $salary_end = $_GET['salary_end'];      //月薪范围上限
        $position = $_GET['position'];          //职位大类
        $position2 = $_GET['position2'];        //职位小类
        $industry = $_GET['industry'];          //行业大类
        $industry2 = $_GET['industry2'];        //行业小类

        $whereSql = "(`is_show`=1) and (`is_del`=0)";
        if(isset($keyword) && !empty($keyword)){
            $whereSql .= " and (`province` like '%".$keyword."%' or `city` like '%".$keyword."%' or `job_name` like '%".$keyword."%')";
        }
        if(isset($years_start) && is_numeric($years_start)){
            switch($years_start){
                case 0:
                case -1:
                    $whereSql .= " and (`work_years`={$years_start})";
                default:
                    $whereSql .= " and (`work_years`>={$years_start})";
            }
        }
        if(isset($years_end) && is_numeric($years_end)){
            $whereSql .= " and (`work_years`<{$years_end})";
        }
        if(isset($date) && intval($date)){
            $today = date('Y-m-d',time()).' 00:00:00';
            $last_time = strtotime("-{$date} day",strtotime($today));
            $last_time = date('Y-m-d H:i:s',$last_time);
            $whereSql .= " and (`created_time`>='{$last_time}')";
        }
        if(isset($edu) && intval($edu)){
            $whereSql .= " and (`education`>={$edu}) ";
        }
        if(isset($salary_start) && is_numeric($salary_start)){
            if($salary_start==0){
                $whereSql .= " and (`salary`=0)";
            }
            else{
                $whereSql .= " and (`salary`>={$salary_start})";
            }
        }
        if(isset($salary_end) && is_numeric($salary_end)){
            $whereSql .= " and (`salary`<{$salary_end}) ";
        }

        if(isset($position2) && intval($position2)){
            $whereSql .= " and (`position_no`>={$position2})";
        }
        else if(isset($position) && intval($position)){
            $whereSql .= " and (`position_no`>={$position})";
        }
        if(isset($industry2) && intval($industry2)){
            $whereSql .= " and (`industry_no`>={$industry2})";
        }
        else if(isset($industry) && intval($industry)){
            $whereSql .= " and (`industry_no`>={$industry})";
        }

        $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
        switch($orderSql){
            case 1: //按更新日排序
                $orderSql = ' `last_updated_time` DESC';
            case 2: //按首发日排序
                $orderSql = ' `created_time` DESC';
            case 3: //按相关度排序
                $orderSql = ' `job_name` DESC';
            default: //按默认排序
                $orderSql = ' `id` DESC';
        }
        $lists = $this->db->listinfo($whereSql,$orderSql,$page,24);
        $count = $this->db->count($whereSql); //统计当前记录总数
        $pages = $this->db->pages;
        $curURL = '/?m=hchhr&c=index&a=init';
        // 获取职位类别
        $position_list = $this->get_position();
        // 获取行业类别
        $industry_list = $this->get_industry();
        include template('hr','index'); //替换模板
    }

    // 异步获取职位类别用
    function load_position(){
        $parent_no = isset($_GET['parent_no'])?$_GET['parent_no']:0;
        $position = $this->get_position($parent_no,'json');
        echo $position;
    }

    // 异步获取行业类别用
    function load_industry(){
        $parent_no = isset($_GET['parent_no'])?$_GET['parent_no']:0;
        $industry = $this->get_industry($parent_no,'json');
        echo $industry;
    }

    function job_details(){
        $userid = param::get_cookie('_userid');
		$jobid = $_GET['jobid'];
        $whereSql = array('id'=>$jobid);
        $job = $this->db->get_one($whereSql,'*');
		$job['job_desc'] = htmlspecialchars_decode($job['job_desc']); 
        include template('hr','job_details'); //替换模板
    }
}
?>